<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
   
    <el-form-item label="教师姓名" prop="teacherId">
      <!-- <el-input v-model="dataForm.teacherId" placeholder="teacher基本信息id"></el-input> -->
       <el-select v-model="dataForm.teacherId" filterable placeholder="请选择">
    <el-option
      v-for="item in options"
      :key="item.value"
      :label="item.name"
      :value="item.id">
    </el-option>
  </el-select>
    </el-form-item>
    <el-form-item label="职称" prop="title">
      <!-- <el-input v-model="dataForm.title" placeholder="职称"></el-input> -->
      <el-select v-model="dataForm.title" clearable placeholder="请选择">
    <el-option
      v-for="item in titles"
      :key="item.value"
      :label="item.label"
      :value="item.value">
    </el-option>
  </el-select>
    </el-form-item>
    <el-form-item label="取得职称资格时间" prop="qualificationTime">
      <!-- <el-input v-model="dataForm.qualificationTime" placeholder="取得职称资格时间"></el-input> -->
      <el-date-picker
      v-model="dataForm.qualificationTime"
      type="datetime"
      placeholder="选择日期时间"
      align="right"
      :picker-options="pickerOptions">
    </el-date-picker>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
         titles: [{
          value: '助教',
          label: '助教'
        }, {
          value: '讲师',
          label: '讲师'
        }, {
          value: '副教授',
          label: '副教授'
        }, {
          value: '教授',
          label: '教授'
        } ],
        options:[],
        visible: false,
        dataForm: {
          id: 0,
          teacherId: '',
          title: '',
          qualificationTime: ''
        },
        dataRule: {
          teacherId: [
            { required: true, message: 'teacher基本信息id不能为空', trigger: 'blur' }
          ],
          title: [
            { required: true, message: '职称不能为空', trigger: 'blur' }
          ],
          qualificationTime: [
            { required: true, message: '取得职称资格时间不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    
     created(){
      this.getteacherInfo() 
     },
     avtived(){
      this.getteacherInfo() 
    },
    methods: {
      getteacherInfo(){
        // 获取教师基本信息
        this.$http({
        url: this.$http.adornUrl('/teacherservice/teachertitle/teacher/info'),
        method: 'get',
        params: this.$http.adornParams({})
        }).then(({data}) => {
          console.log(data)
          this.options=data.data
          console.log("jdvnd",this.options)
        })
      

      },

      
      init (id) {
        this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            this.$http({
              url: this.$http.adornUrl(`/teacherservice/teachertitle/info/${this.dataForm.id}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.teacherId = data.teacherTitle.teacherId
                this.dataForm.title = data.teacherTitle.title
                this.dataForm.qualificationTime = data.teacherTitle.qualificationTime
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/teacherservice/teachertitle/${!this.dataForm.id ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'id': this.dataForm.id || undefined,
                'teacherId': this.dataForm.teacherId,
                'title': this.dataForm.title,
                'qualificationTime': this.dataForm.qualificationTime
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
